﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;

namespace eTerm.NetSocket.Net
{
    public class HttpWebClient : WebClient
    {
        private CookieContainer cookies;

        public HttpWebClient()
        {
            this.cookies = new CookieContainer();
        }

        public HttpWebClient(CookieContainer cookies)
        {
            this.cookies = cookies;
        }

        public CookieContainer Cookies
        {
            get
            {
                return this.cookies;
            }
            set
            {
                this.cookies = value;
            }
        }

        protected override WebRequest GetWebRequest(Uri address)
        {
            WebRequest request = base.GetWebRequest(address);

            if (request is HttpWebRequest)
            {
                HttpWebRequest httpRequest = request as HttpWebRequest;
                httpRequest.CookieContainer = cookies;
            }
            return request;
        }
    }
}
